GMMMPEC_f_grad_ktr_FE <- function(x) { 

x<-as.matrix(x)  
  
g = x[((nD+1)*(K_A+1) + (countries-1) + nD + numProdsTotal+1):nrow(x), 1]   

f = t(g)%*%W%*%g 

nx = nrow(x)
grad_f<-matrix(0,nx,1)
grad_f[((nD+1)*(K_A+1) + (countries-1) + nD + numProdsTotal +1):nrow(grad_f), 1] = 2*W%*%g
grad_f<-as.numeric(grad_f)

return(grad_f)
  
}  



